package com.joysuch.wwyt.core.common.util;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;

public class ErrorCheck extends RuntimeException {

    public static void check(Boolean b, String msg) {
        if (b) {
            throw new RuntimeException(msg);
        }
    }

    public static void check(Object obj, String msg) {
        if (ifTrue(obj)) {
            throw new RuntimeException(msg);
        }
    }

    public static boolean ifTrue(Object obj) {
        if (obj == null) {
            return true;
        } else if (obj instanceof CharSequence) {
            return ((CharSequence) obj).length() == 0;
        } else if (obj instanceof Collection) {
            return ((Collection) obj).isEmpty();
        } else if (obj instanceof Map) {
            return ((Map) obj).isEmpty();
        } else if (obj.getClass().isArray()) {
            return Array.getLength(obj) == 0;
        }
        return false;
    }
}
